<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title></title>
    <script src='./vue.global.js'></script>
</head>
<body>
    <div id='app'>
        <custom-form @login="onLogin"></custom-form>
    </div>

    
    <script>
        const app = Vue.createApp({
            data(){
                return {}
            },
            methods:{
                onLogin(e){
                    console.log("onLogin",e);
                }
            },
            computed:{}
        })

        app.component("custom-form",{
            /* 声明向父组件发送哪些自定义事件 */
            // emits:["login"],

            emits:{
                // 无需校验的事件类型
                click:null,

                // 自定义事件login必须经过函数的校验 结果返回true代表通过校验
                login:(e)=>{
                    // return true
                    // return false

                    if(e.username && e.password){
                        return true
                    }else{
                        console.error("非法的登录事件参数:必须携带username和password");
                        return false
                    }
                }
            },
            template:`
            <button @click="$emit('login',{msg:'今晚去哪嗨?'})">login</button>
            <button @click="$emit('login',{username:'admin',password:'123456'})">login</button>
            `
        })

        app.mount('#app')
    </script>
</body>
</html>